package gui.components;

import java.awt.Window;

import javax.swing.SwingUtilities;

import negotiator.Negotiator;

import lombok.Setter;

/**
 * Dialog ustawiajacy czas oczekiwania zgloszen w kolejce
 * @author Witold Muszynski
 *
 */
public class WaitTimeDialog extends javax.swing.JDialog {

    /** Creates new form History */
    public WaitTimeDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
    	  jLabel1 = new javax.swing.JLabel();
          jSpinner1 = new javax.swing.JSpinner();
          jButton1 = new javax.swing.JButton();
          jLabel2 = new javax.swing.JLabel();

          setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
          setBounds(new java.awt.Rectangle(400, 200, 0, 0));

          jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
          jLabel1.setText("Zmien dlugosc czasu oczekiwania na zamowienia");

          jButton1.setText("Zatwierdz");
          jButton1.addActionListener(new java.awt.event.ActionListener() {
	            public void actionPerformed(java.awt.event.ActionEvent evt) {
	                int value = (int) jSpinner1.getValue();
	                jSpinner1.setValue(0);
	                setWaitTime(value);
	                closeWindow();
	            }
	        });

          jLabel2.setText("sekund");

          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
          getContentPane().setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)
              .addGroup(layout.createSequentialGroup()
                  .addGap(71, 71, 71)
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                      .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                      .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                          .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                          .addComponent(jLabel2)))
                  .addContainerGap(60, Short.MAX_VALUE))
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                  .addContainerGap()
                  .addComponent(jLabel1)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(jLabel2))
                  .addGap(18, 18, 18)
                  .addComponent(jButton1)
                  .addContainerGap(24, Short.MAX_VALUE))
          );

        pack();
    }// </editor-fold>
    
private void closeWindow(){
		Window window = SwingUtilities.getWindowAncestor(jButton1);
		this.dispose();
		this.setVisible(false);
	}


private void setWaitTime(int value){
	if (value > 0)
		Negotiator.changeWaitTime(value); 
	
}

    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JSpinner jSpinner1;
}